package com.service.impl;

import com.entity.Admin;
import com.mapper.AdminMapper;
import com.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("adminService")
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public boolean login(String name, String pwd) {
        Admin admin = adminMapper.selectAdminByName(name);
        if(admin != null && admin.getPassword().equals(pwd)){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean register(String name, String password) {
        if(name != null){
            adminMapper.insertAdmin(new Admin(null,name,password));
            return true;
        }else{
            return false;
        }
    }

    @Override
    public void insertAdmin(Admin admin) {
        adminMapper.insertAdmin(admin);
    }

    @Override
    public void deleteAdminById(Integer id) {
        adminMapper.deleteAdminById(id);
    }

    @Override
    public void updateAdmin(Admin admin) {
        adminMapper.updateAdmin(admin);
    }

    @Override
    public Admin selectAdminById(Integer id) {
        return adminMapper.selectAdminById(id);
    }

    @Override
    public Admin selectAdminByName(String name) {
        return adminMapper.selectAdminByName(name);
    }

    @Override
    public List<Admin> selectAdmin() {
        return adminMapper.selectAdmin();
    }

    @Override
    public List<Admin> selectPageAdmin(Integer pageNum, Integer pageSize) {
        return adminMapper.selectPageAdmin(pageNum,pageSize);
    }
}
